package cn.restcloud.example.controller;

import cn.restcloud.mqbus.util.rabbitmq.RabbitmqUtil;
import com.rabbitmq.client.*;
import java.util.LinkedList;

public class RabbitMqTest {

    public void sendMsg() throws Exception {
        Connection connection = null;
        int size = 1000;
        try {
            connection = RabbitmqUtil.createConnection("192.168.8.47", "hryuan", "admin", 5672, "testhost");
            Channel channel = connection.createChannel();
            for (int i = 0; i < size; i++) {
                RabbitmqUtil.sendString(channel, "TEST_QUEUE_02", "test Message" + i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            RabbitmqUtil.closeConnection(connection);
        }
    }

    public void getMsg() throws Exception {
        Connection connection = null;
        try {
            connection = RabbitmqUtil.createConnection("192.168.8.47", "hryuan", "admin", 5672, "testhost");
            LinkedList<String> list = RabbitmqUtil.receiveBySize(connection.createChannel(), "TEST_QUEUE_02", 10, "utf-8", true);
            System.out.println(list);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            RabbitmqUtil.closeConnection(connection);
        }
    }


}